package com.zzxx.controller;

import com.github.pagehelper.PageInfo;
import com.zzxx.domain.Permission;
import com.zzxx.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping("permission")
public class PermissionController {
    @Autowired
    private PermissionService permissionService;
    @RequestMapping("findAll")
    public String findAll(Model model,
                          @RequestParam(name = "pageNum", required = true, defaultValue = "1") Integer pageNum,
                          @RequestParam(name = "pageSize", required = true, defaultValue = "4") Integer pageSize){
        List<Permission> permissionList = permissionService.queryAll(pageNum, pageSize);
        PageInfo<Permission> permissionPageInfo = new PageInfo<>(permissionList);
        model.addAttribute("permissionPageInfo", permissionPageInfo);
        return "permission-list";
    }

    @RequestMapping("add")
    public String add(Permission permission){
        permissionService.add(permission);
        return "redirect:/permission/findAll";
    }
}
